package com.tanhua.server.controller;

import com.tanhua.server.service.ManageService;
import com.tanhua.server.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("manage")
public class ManageController {

    @Autowired
    private ManageService manageService;

    /**
     * 评论列表翻页
     * @param page 当前页
     * @param pagesize 每页显示条数
     * @param messageID 消息ID
     * @param sortProp 排序字段
     * @param sortOrder ascending 升序 descending 降序
     * @return
     */
    @GetMapping("messages/comments")
    public ResponseEntity queryCommentList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                           @RequestParam(value = "pagesize", defaultValue = "10") Integer pagesize,
                                           @RequestParam("messageID") String messageID,
                                           @RequestParam("sortProp") String sortProp,
                                           @RequestParam("sortOrder") String sortOrder){
        //调用service查询评论数据
        PageResult pageResult = manageService.queryCommentList(page, pagesize, messageID, sortProp, sortOrder);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 视频记录翻页
     * @param page 当前页
     * @param pagesize 每页显示条数
     * @param uid ID 当前发布视频的用户id
     * @param sortProp 排序字段
     * @param sortOrder ascending 升序 descending 降序
     * @return
     */
    @GetMapping("videos")
    public ResponseEntity queryVideosList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                          @RequestParam(value = "pagesize", defaultValue = "10") Integer pagesize,
                                          @RequestParam("uid") Long uid,
                                          @RequestParam("sortProp") String sortProp,
                                          @RequestParam("sortOrder") String sortOrder){
        //调用service查询视频数据
        PageResult pageResult = manageService.queryVideosList(page, pagesize, uid, sortProp, sortOrder);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 日志翻页
     * @param page 当前页
     * @param pagesize 每页显示数
     * @param uid 发布动态的用户id
     * @param sortProp 排序字段
     * @param sortOrder sortOrder ascending 升序 descending 降序
     * @return
     */
    @GetMapping("logs")
    public ResponseEntity queryLogsList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                        @RequestParam(value = "pagesize", defaultValue = "10") Integer pagesize,
                                        @RequestParam("uid") Long uid,
                                        @RequestParam("sortProp") String sortProp,
                                        @RequestParam("sortOrder") String sortOrder){
        //调用service查询视频数据
        PageResult pageResult = manageService.queryLogsList(page, pagesize, uid, sortProp, sortOrder);
        return ResponseEntity.ok(pageResult);
    }


}
